<template>
    <Form ref="loginForm" :model="form" :rules="rules" @keydown.enter.native="handleSubmit">
        <FormItem prop="userName">
            <Input v-model="form.userName" placeholder="用户名">
            <!--<span slot="prepend">
              <Icon :size="16" type="ios-person"></Icon>
            </span>-->
            </Input>
        </FormItem>
        <FormItem prop="password" class="wl-pwd">
            <Input type="password" v-model="form.password" placeholder="密码">
            <!--<span slot="prepend">
              <Icon :size="14" type="md-lock"></Icon>
            </span>-->
            </Input>
        </FormItem>
        <FormItem class="btn-group">
            <Button class="set-button-color" @click="handleSubmit" type="primary" long>登录</Button>
        </FormItem>
    </Form>
</template>
<script>
export default {
  name: 'LoginForm',
  props: {
    userNameRules: {
      type: Array,
      default: () => {
        return [
          { required: true, message: '账号不能为空', trigger: 'blur' }
        ]
      }
    },
    passwordRules: {
      type: Array,
      default: () => {
        return [
          { required: true, message: '密码不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  data () {
    return {
      form: {
        userName: 'shenyang',
        password: ''
      }
    }
  },
  computed: {
    rules () {
      return {
        userName: this.userNameRules,
        password: this.passwordRules
      }
    }
  },
  methods: {
    handleSubmit () {
      this.$refs.loginForm.validate((valid) => {
        if (valid) {
          this.$emit('on-success-valid', {
            userName: this.form.userName,
            password: this.form.password
          })
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
    @import '../index.less';

    .btn-group {
        padding-top: 20px;
    }

    /deep/.ivu-input {
        height: 40px;
    }

    /deep/.ivu-btn {
        height: 40px;
    }

    /deep/.ivu-btn-primary {
        border: 0px;
        background:linear-gradient(to right,#abdcff,#43EEFF,#3AB0FA,#39A0FC)
    }

    /deep/.ivu-btn-primary span {
        color: #000008;
    }
</style>
